<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Plots a cantilever beam as a 3D figure.</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/cvxbook/Ch04_cvx_opt_probs/html/cantilever_beam_plot.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Plots a cantilever beam as a 3D figure.</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
Text output
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% This is a helper function for the optimal cantilever beam example.</span>
<span class="comment">%</span>
<span class="comment">% Inputs:</span>
<span class="comment">%    values: an array of heights and widths of each segment</span>
<span class="comment">%            [h1 h2 ... hN w1 w2 ... wN]</span>
<span class="comment">%</span>
<span class="comment">% Almir Mutapcic 01/25/06</span>

<span class="keyword">function</span> cantilever_beam_plot(values)

N = length(values)/2;
<span class="keyword">for</span> k = 0:N-1
  [X Y Z] = data_rect3(values(2*N-k),values(N-k),k);
  plot3(X,Y,Z); hold <span class="string">on</span>;
<span class="keyword">end</span>
hold <span class="string">off</span>;

xlabel(<span class="string">'width'</span>)
ylabel(<span class="string">'height'</span>)
zlabel(<span class="string">'length'</span>)
<span class="keyword">return</span>;

<span class="comment">%****************************************************************</span>
<span class="keyword">function</span> [X, Y, Z] = data_rect3(w,h,d)
<span class="comment">%****************************************************************</span>
<span class="comment">% back face</span>
X = [-w/2 w/2 w/2 -w/2 -w/2];
Y = [-h/2 -h/2 h/2 h/2 -h/2];
Z = [d d d d d];
<span class="comment">% side face</span>
X = [X -w/2 -w/2 -w/2 -w/2 -w/2];
Y = [Y -h/2 -h/2 h/2 h/2 -h/2];
Z = [Z d d+1 d+1 d d];
<span class="comment">% front face</span>
X = [X -w/2 w/2 w/2 -w/2 -w/2];
Y = [Y -h/2 -h/2 h/2 h/2 -h/2];
Z = [Z d+1 d+1 d+1 d+1 d+1];
<span class="comment">% back side face</span>
X = [X w/2 w/2 w/2 w/2 w/2];
Y = [Y -h/2 h/2 h/2 -h/2 -h/2];
Z = [Z d+1 d+1 d d d+1];
</pre>
</div>
</body>
</html>